package com.sgcc.system.api.factory;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import com.sgcc.common.core.domain.R;
import com.sgcc.common.core.web.domain.AjaxResult;
import com.sgcc.common.core.web.page.TableDataInfo;
import com.sgcc.system.api.RemoteUserService;
import com.sgcc.system.api.domain.SysUser;
import com.sgcc.system.api.model.LoginUser;
import feign.hystrix.FallbackFactory;

/**
 * 用户服务降级处理
 * 
 * @author sgcc
 */
@Component
public class RemoteUserFallbackFactory implements FallbackFactory<RemoteUserService>
{
    private static final Logger log = LoggerFactory.getLogger(RemoteUserFallbackFactory.class);

    @Override
    public RemoteUserService create(Throwable throwable)
    {
        log.error("用户服务调用失败:{}", throwable.getMessage());
        return new RemoteUserService()
        {
            @Override
            public R<LoginUser> getUserInfo(String username)
            {
                return R.fail("获取用户失败:" + throwable.getMessage());
            }

			@Override
			public TableDataInfo selectUserList(SysUser user) {
				// TODO Auto-generated method stub
				TableDataInfo r=new TableDataInfo();
				r.setCode(500);
				r.setMsg("获取用户列表失败，请重启服务~");
				return r;
			}

			@Override
			public TableDataInfo selectUserListByRoleKey(String roleKey) {
				// TODO Auto-generated method stub
				TableDataInfo r=new TableDataInfo();
				r.setCode(500);
				r.setMsg("获取用户列表失败，请重启服务~");
				return r;
			}

			@Override
			public SysUser selectUserByUserName(String userId) {
				// TODO Auto-generated method stub
				return null;
			}

			@Override
			public R<Integer> addIsc(SysUser user) {
				// TODO Auto-generated method stub
				return R.fail("ISC插入用户失败，请稍后再试~");
			}

			@Override
			public R<Integer>  editIsc(SysUser user) {
				// TODO Auto-generated method stub
				return R.fail("ISC更新用户失败，请稍后再试~");
			}

			@Override
			public R<SysUser>  getInfoISC(String id) {
				// TODO Auto-generated method stub
				return R.fail("ISC查询用户失败，请稍后再试~");
			}



			@Override
			public AjaxResult insertUserRole(String userId, String ids) {
				// TODO Auto-generated method stub
				return AjaxResult.error("ISC插入用户角色");
			}

			@Override
			public SysUser selectUserByUserId(String id) {
				System.out.println(throwable.getMessage());
				return null;
			}


		};
    }
}
